﻿@using ZBJF.Warranty.BLL
@using ZBJF.Warranty.Model
@using ZBJF.Warranty.WebProvider
@{
    ViewBag.Title = "Index";
}
@section Header{
    @Scripts.Render("~/bundles/wdate")
    @Scripts.Render("~/bundles/datatable")
    @Scripts.Render("~/bundles/chosen")
    @Styles.Render("~/Content/datatable")
    @Styles.Render("~/Content/chosen")
}
<form id="searchForm" class="breadcrumb form-search">
    <div>
        <label>是否可用:</label>
        @Html.DropDownList("IsAvailable", ConvertToSelector.Instance.InitSelectList(true), new { @class = "tag-input-style" })
        <label>Keywords</label><input id="Keyword" name="Keyword" class="input-medium" placeholder="请输入搜索关键词" type="text" value="" maxlength="50" />
        <input id="btnSubmit" class="btn btn-primary Search-R" type="button" value="Search" onclick="search();">
    </div>
</form>
<div class="table-responsive dataTables_wrapper">
    <table id="productBrandsList" class="table table-striped table-bordered table-hover">
        <thead>
            <tr>
                <th width="20">No.</th>
                <th width="100">品牌名称</th>
                <th width="100">图片</th>
                <th width="80">创建时间</th>
                <th width="80">修改时间</th>
                <th width="100">备注</th>
                <th width="100">排序</th>
                <th width="80">是否可用</th>
                <th width="100">操作</th>
            </tr>
        </thead>
    </table>
</div>
<div class="form-actions control-group align-center">
    <input id="btnConfirm" class="btn btn-primary Edit-R" type="submit" value="确认">
    <input id="btnClose" class="btn" type="button" value="取消" onclick="parent.layer.closeAll()">
</div>
@section scripts{
    @Scripts.Render("~/bundles/datatable")
    @Styles.Render("~/Content/datatable")
    @Scripts.Render("~/Bundles/ImagePreview")
    <script type="text/javascript">
        var isSearch = false;
        $(function () {
            var objTable = $("#productBrandsList")
                .dataTable({
                    fnDrawCallback: function () {
                        ControlPermissionOperate();
                    },
                    "sAjaxSource": "/ProductBrands?IsAvailable=true&ProductBrandID=@(Request["ProductBrandID"])",
                    "iDisplayLength": 10, //首次加载的数据条数
                    aoColumns: [
                        {
                            "mData": null,
                            "bSortable": false,
                            "fnRender": function (nRow) {
                                return "<input type='checkbox' name='checkList' class='CheckBoxItem' value='" + nRow.aData.ID + "'>";
                            }
                        },
                        {
                            "mData": null,
                            "bSortable": false,
                            "fnRender": function (nRow) {
                                return nRow.iDataRow + 1;
                            }
                        },
                        {
                            "mData": "ModelName",
                            "fnRender": function (nRow) {
                                return "<a class='Edit-R' target='_blank' href='/ProductBrands/Edit/" + nRow.aData.ID + "' title='edit'>" + nRow.aData.ModelName + "</a>";
                            }
                        },
                        { "mData": "ModelDisplayName" },
                        { "mData": "IsHot" },
                        { "mData": "RecycleFlag" },
                        { "mData": "PartsFlag" },
                        {
                            "mData": "ImgUrl",
                            "bSortable": false,
                            "fnRender": function (nRow) {
                                if (nRow.aData.ImgUrl && nRow.aData.ImgUrl !== '')
                                    return "<img class='img-thumbnail small preview' src='" + nRow.aData.ImgUrl + "'/>";
                                else {
                                    return "";
                                }
                            }
                        }
                    ],
                    "fnRowCallback": function (nRow, aData, iDisplayIndex) {
                        $('td:eq(4)', nRow).html(aData.IsHot ? bootStrapOkIncon : bootStrapRemoveIncon);
                        $('td:eq(5)', nRow).html(aData.RecycleFlag ? bootStrapOkIncon : bootStrapRemoveIncon);
                        $('td:eq(6)', nRow).html(aData.PartsFlag ? bootStrapOkIncon : bootStrapRemoveIncon);
                    }
                });

            initCheckBoxItem("productBrandsList", "@(Request["multiselect"] == "true")");

            function getProductBrands() {
                var nTrs = objTable.fnGetNodes(); //fnGetNodes获取表格所有行，nTrs[i]表示第i行tr对象
                var partsModelArr = [];
                for (var i = 0; i < nTrs.length; i++) {
                    if ($(nTrs[i]).hasClass('selected')) {
                        partsModelArr.push(objTable.fnGetData(nTrs[i]));
                    }
                }
                return partsModelArr;
            }

            $("#btnConfirm").click(function () {
                parent.setSelectProductBrands(getProductBrands());
                parent.layer.closeAll();
            });

            imgPreview();
        });

        function imgPreview() {
            setTimeout(function () { $("img.preview").preview(); }, 500);
        }

        function search() {
            /*给查询对象赋值*/
            queryParamList.Keyword = ($("#Keyword").val());
            queryParamList.IsAvailable = ($("#IsAvailable").val());
            $("#productBrandsList").dataTable().fnDraw();
            imgPreview();
        }
    </script>
}


